package com.saodisheng.service.impl;

import com.jfinal.plugin.activerecord.Db;
import com.saodisheng.model.Posts;
import com.saodisheng.model.PostsComment;
import com.saodisheng.model.Tags;
import com.saodisheng.model.User;
import com.saodisheng.service.AdminIndexService;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class AdminIndexServiceImpl implements AdminIndexService {
	final Posts postsDao = new Posts().dao();
	final User userDao = new User().dao();
	final PostsComment postsComment = new PostsComment().dao();
	final Tags tagDao = new Tags().dao();
	

	@Override
	public long getPostNum() {
		long postNum = 0;
		postNum = Db.queryLong("select count(id) from posts");
		return postNum;
	}

	@Override
	public long getCommentNum() {
		long commentNum = Db.queryLong("select count(id) from posts_comment");
		return commentNum;
	}
	

	@Override
	public long getUserNum() {
		long userNum = Db.queryLong("select count(id) from user");
		return userNum;
	}

	@Override
	public long getTagNum() {
		long tagNum = Db.queryLong("select count(id) from tags");
		return tagNum;
	}

	@Override
	public long getPostNumByType(int type) {
		long artcielNum = Db.queryLong("select count(*) from posts where post_type=?", type);
		return artcielNum;
	}

	@Override
	public List<User> getUserList(int num) {
		List<User> users= userDao.find("select * from user order by createAt desc limit ?", num);
		return users;
	}

	@Override
	public List<Posts> getPostList(int num) {
		List<Posts> posts = postsDao.find("select * from posts order by createAt desc limit ?", num);
		return posts;
	}
	
}
